home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
me_cd25.zip
/
DOC.ZIP
/
MUTT2.DOC
< prev
next >
Wrap
Text File
|
1992-11-09
|
38KB
|
923 lines
========================================================================
== The Mutt2 Programming Language Craig Durland 9/89 10/91 ==
========================================================================
Here is the documentation for the core Mutt2 programming language.
There are probably many extensions, depending on what application Mutt
is embedded in. See the documentation for the application for more info.
Copyright 1991 Craig Durland
Distributed under the terms of the GNU General Public License.
Distributed "as is", without warranties of any kind, but comments,
suggestions and bug reports are welcome.
======================================================================
== Syntax ==
======================================================================
symbol action
( evaluate expression
) end expression
{ start block
} end block
SYNTAX
pgm : {exp [exp ...]}, {}
exp : (fcn [args]), (var [args]), var, const, ()
const : number (123, 0xAbC), string ("abc", 'abc'), TRUE, FALSE
arg : block
block : pgm, exp or const
fcn : a Mutt function (such as + or while) or defined function.
======================================================================
== Data Types ==
======================================================================
Mutt is a typed language.
Type id What it is
---- -- ---- -- --
BOOLEAN 0x05 TRUE or FALSE.
BLOB 0x06 A pointer to a block of data.
NUMBER 0x03 32 bit signed integer.
STRING 0x08 A bunch of characters.
LIST 0x09 A list of things.
VOID 0x01 A type of nothing.
FCNPTR 0x07 A pointer to a function.
CHARACTER 0x0A This is not a real data type. It is a helper
type.
REAL 0x04 Not implemented.
Id is a numeric constant that is used to identify a data type. They are
used in Mutt programs when you need to talk about types (see
convert-to).
List Syntax
Sometimes I'll need to refer to the contents of a list. To do that,
I'll use [<first element> <next element> ...]. Everything in "[]"
are the contents of the list. "[]" by itself means the empty list.
======================================================================
== Return Values ==
======================================================================
All blocks "return" a value. Pgms return the value of the last exp
executed. Note that a pgm can return values of different types.
The class of a return value can be one of:
BOOLEAN, BLOB, NUMBER, STRING, LIST, VOID, FCNPTR.
======================================================================
== Variables (aka vars) ==
======================================================================
CREATION
Vars must be created before they can be used.
Global vars are initialized to:
bool : FALSE
int, small-int, byte : 0
string : ""
list : empty
Most Local vars are NOT initialized (ie they contain garbage when
created). Local strings and lists are initialized the same as
globals.
EVALUATION & ASSIGNMENT
Vars behave like fcns, ie (var) evaluates the var (returns its value)
and (var val) passes val to the var for assignment. (var val)
returns val. If you just want to evaluate a var, you can treat it
like a const - ie "var" is equivalent to "(var)". Note, however,
doing this may cause logic bugs if var also happens to be the name
of a const (since the const is locked out). See GOTCHAS. In some
cases, (var) and var don't mean the same thing - see pointer.
Cascading assignment: you can assign multiple vars the same value.
eg (int x y z)(x (y (z 123))) assigns 123 to x, y and z.
eg (int x)(string s 20)(x (convert-to NUMBER (s "123"))) sets s to
"123" and x to 123.
SCOPE
The scope of a variable is the same as the pgm it is created in.
A variable created outside of a fcn (defun) is global - ie anybody
can get at it. Global variables are local to the file (and any
included file(s)) they are created in.
For example:
If foo.mut contains:
(int foo) ; declare and create global var "foo"
(defun "hoho" { (int bar) (bar foo) })
(foo 123) ; assign 123 to foo
(load "foo.mut") will create a global var foo. (hoho)
creates bar and sets it to 123. hoho is done and bar is freed.
foo is still alive and equal to 123.
======================================================================
== Functions and Keywords ==
======================================================================
Everything in this list is a function (except those that have a return
class of zip).
A TOKEN is a bunch of letters, eg foo.
(KEYWORD args) [arg class(s) : return class]
-------- ----- ---- -------- - ------ ------
; (semi-colon) A comment that extends to the end of the line
(== value value ...) [STRINGs, NUMBERs or BOOLEANs : BOOLEAN]
Test 2 or more items for equality.
You can only compare like types - eg (== "123" 123) is illegal.
eg (== foo 1), (== "one" "two"), (== (+ foo 3) bar 5).
(!= value value) [NUMBER NUMBER : BOOLEAN]
Same as == but nonequality. Only 2 items.
(< value1 value2) TRUE if value1 < value2. [NUMBER NUMBER : BOOLEAN]
(<= value1 value2) TRUE if value1 <= value2. [NUMBER NUMBER : BOOLEAN]
(> value1 value2) TRUE if value1 > value2. [NUMBER NUMBER : BOOLEAN]
(>= value1 value2) TRUE if value1 >= value2. [NUMBER NUMBER : BOOLEAN]
(+ values) [NUMBERs : NUMBER]
Add a bunch of numbers eg (+ 1 2 3 4) => 1+2+3+4
(- values) [NUMBERs : NUMBER]
Subtract a bunch of numbers eg (- 1 2 3 4) => 1-2-3-4 = -8
(* values) multiply a bunch of numbers [NUMBERs : NUMBER]
(/ values) divide a bunch of numbers [NUMBERs : NUMBER]
(+= var values) [TOKEN NUMBERs : NUMBER]
Add value(s) to var and assign it back to the var. Returns the result.
Short hand for (var (+ var values)).
eg (+= foo 1) (+= foo fud 3)
(-= var values) Subtract value from var. [TOKEN NUMBERs : NUMBER]
(*= var values) Multiply var by value. [TOKEN NUMBERs : NUMBER]
(/= var values) Divide var by value. [TOKEN NUMBERs : NUMBER]
"string"
String constant.
Special characters:
\ quote the next character. "\\" => '\' "\^" => '^'
^ convert the next character to a control character (make sure that
the letter is UPPERCASE!). eg "^A"
Note: escape == ^[.
'string'
String constant.
No special characters except '' reduces to ' ie if you need a string
like "don't", you can use 'don''t'.
This form is handy for regular expressions.
(and values) [BOOLEAN [BOOLEAN ...] : BOOLEAN]
Logically and a bunch of things
The first FALSE value will terminate (ie the rest of the and will
not be evaluated).
Example:
(and (previous-line) (foo)): If previous-line returns TRUE, foo is
called and that will be the result of the and. If previous-line
returns FALSE, the and returns FALSE and foo is not called.
See also: or.
(arg n) [NUMBER : any class]
Get the nth argument from the parameter list.
The arguments are numbered 0,1...,(nargs)-1
eg (fcn 1 "two" (three)) has 3 arguments: numeric 1, string "two" and
whatever fcn three returns. (arg 0) returns 1, (arg 1) returns
"two", (arg 2) returns result of (three). (arg 3), (arg -1), etc
error.
Notes:
You cannot set a arg unless it is a pointer.
See defun for how you can name the args.
See also: ask, defun, nargs.
(array type name dimensions) [TOKEN TOKEN NUMBERs [TOKEN NUMBERs] : zip]
Create an array. Types allowed: bool, int, small-int.
(array int x 5 z 7) creates two arrays: x with 5 ints and z with 7.
(array int y 2 3) creates an array with 2 rows of 3 ints each.
(x 3 123) sets the third element of x to 123.
(x 3) returns 123.
(ask prompt(s)) [any class(s) ... : STRING]
Get the next argument from the argument list; if the argument list is
empty, query the user. Away